//# sourceURL=http://uMapApp/Module/HomeNSModule
define([
    "mhjs/mhjs",
    "uMap/uMap",
    "uEarth/uEarth",
    "../Module",
    "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/ChartBlock"
], function (
    mhjs,
    uMap,
    uEarth,
    Module,
    FloatPanel,
    ChartBlock
) {

    function HomeNSModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "无形资产";
        _this.icon = _this.app.icons.home;

        _this.leftPanel = new FloatPanel({"class": "leftPanel", "showMinMax": true, "title": "里程 / 技术状况 / 病害"});

        _this.leftPanel.lengthChartBlock = new ChartBlock({
            "title": "道路里程数变化统计",
            "chart": {
                "height"     : 220,
                "width"      : 350,
                "chartOption": {
                    legend: {
                        textStyle: {
                            color: "#fff"
                        },
                        data     : [
                            "通车20年以上",
                            "通车15-20年",
                            "通车10-15年",
                            "通车5-10年",
                            "通车5年以下"
                        ]
                    },
                    grid  : {
                        top         : "80px",
                        left        : "0",
                        right       : "40px",
                        bottom      : "0",
                        containLabel: true
                    },
                    xAxis : {
                        name: "年段",
                        type: "category",
                        data: ["≥20", "[15,20]", "[10,15]", "[5,10]", "<5"]
                    },
                    yAxis : {
                        name    : "公里",
                        type    : "value",
                        axisLine: {
                            show: true
                        }
                    },
                    series: [
                        {
                            name   : "通车20年以上",
                            type   : "bar",
                            colorBy: "data",
                            stack  : "total",
                            label  : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            data   : [0]
                        },
                        {
                            name   : "通车15-20年",
                            type   : "bar",
                            colorBy: "data",
                            stack  : "total",
                            label  : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            data   : [0, 134]
                        },
                        {
                            name   : "通车10-15年",
                            type   : "bar",
                            colorBy: "data",
                            stack  : "total",
                            label  : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            data   : [0, 0, 57]
                        },
                        {
                            name   : "通车5-10年",
                            type   : "bar",
                            colorBy: "data",
                            stack  : "total",
                            label  : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            data   : [0, 0, 0, 22]
                        },
                        {
                            name   : "通车5年以下",
                            type   : "bar",
                            colorBy: "data",
                            stack  : "total",
                            label  : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            data   : [0, 0, 0, 0, 28]
                        }
                    ]
                }
            }
        });

        _this.leftPanel.PQIChartBlock = new ChartBlock({
            "title": "路面技术状况变化统计",
            "chart": {
                "height"     : 270,
                "width"      : 350,
                "chartOption": {
                    legend: {
                        textStyle: {
                            color: "#fff"
                        },
                        data     : ["优", "良", "中", "次", "差"]
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    grid  : {
                        top         : "30px",
                        left        : "0",
                        right       : "40px",
                        bottom      : "0",
                        containLabel: true
                    },
                    xAxis : {
                        name       : "年",
                        type       : "category",
                        boundaryGap: false,
                        data       : [2016, 2017, 2018, 2019, 2020, 2021, 2022]
                    },
                    yAxis : {
                        name     : "PQI",
                        type     : "value",
                        interval : 20,
                        min      : 0,
                        max      : 100,
                        axisLabel: {
                            formatter: function (param) {
                                return ["优", "良", "中", "次", "差"][5 - param / 20];
                            }
                        },
                        axisLine : {
                            show: true
                        }
                    },
                    series: [
                        {
                            type  : "line",
                            smooth: true,
                            data  : [70, 45, 90, 75, 94.3, 94.23, 94.39]
                        },
                        {
                            name      : "差",
                            type      : "line",
                            stack     : "Total",
                            lineStyle : {
                                width: 0
                            },
                            showSymbol: false,
                            areaStyle : {
                                opacity: 0.2
                            },
                            data      : [20, 20, 20, 20, 20, 20, 20, 20]
                        },
                        {
                            name      : "次",
                            type      : "line",
                            stack     : "Total",
                            lineStyle : {
                                width: 0
                            },
                            showSymbol: false,
                            areaStyle : {
                                opacity: 0.2
                            },
                            data      : [20, 20, 20, 20, 20, 20, 20, 20]
                        },
                        {
                            name      : "中",
                            type      : "line",
                            stack     : "Total",
                            lineStyle : {
                                width: 0
                            },
                            showSymbol: false,
                            areaStyle : {
                                opacity: 0.2
                            },
                            data      : [20, 20, 20, 20, 20, 20, 20, 20]
                        },
                        {
                            name      : "良",
                            type      : "line",
                            stack     : "Total",
                            lineStyle : {
                                width: 0
                            },
                            showSymbol: false,
                            areaStyle : {
                                opacity: 0.2
                            },
                            data      : [20, 20, 20, 20, 20, 20, 20, 20]
                        },
                        {
                            name      : "优",
                            type      : "line",
                            stack     : "Total",
                            lineStyle : {
                                width: 0
                            },
                            showSymbol: false,
                            areaStyle : {
                                opacity: 0.2
                            },
                            data      : [20, 20, 20, 20, 20, 20, 20, 20]
                        }
                    ]
                }
            }
        });

        _this.leftPanel.roadDamageChartBlock = new ChartBlock({
            "title": "道路病害变化统计",
            "chart": {
                "height"     : 270,
                "width"      : 350,
                "chartOption": {
                    legend: {
                        data: [
                            {name: "≥100", icon: "roundRect"},
                            {name: "[60,100]", icon: "roundRect"},
                            {name: "[30,60]", icon: "roundRect"},
                            {name: "[15,30]", icon: "roundRect"},
                            {name: "<15", icon: "roundRect"}
                        ]
                    },
                    grid  : {
                        top         : "80px",
                        left        : "0",
                        right       : "40px",
                        bottom      : "0",
                        containLabel: true
                    },
                    xAxis : {
                        name: "mm",
                        type: "category",
                        data: ["≥100", "[60,100]", "[30,60]", "[15,30]", "<15"]
                    },
                    yAxis : {
                        name    : "公里",
                        type    : "value",
                        axisLine: {
                            show: true
                        }
                    },
                    series: [
                        {
                            name          : "≥100",
                            type          : "pictorialBar",
                            barCategoryGap: "-50%",
                            symbol        : "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
                            label         : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            itemStyle     : {
                                opacity: 0.5
                            },
                            data          : [395.32]
                        },
                        {
                            name          : "[60,100]",
                            type          : "pictorialBar",
                            barCategoryGap: "-50%",
                            symbol        : "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
                            label         : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            itemStyle     : {
                                opacity: 0.5
                            },
                            data          : [0, 230.14, 0, 0, 0]
                        },
                        {
                            name          : "[30,60]",
                            type          : "pictorialBar",
                            barCategoryGap: "-50%",
                            symbol        : "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
                            label         : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            itemStyle     : {
                                opacity: 0.5
                            },
                            data          : [0, 0, 175.1, 0, 0]
                        },
                        {
                            name          : "[15,30]",
                            type          : "pictorialBar",
                            barCategoryGap: "-50%",
                            symbol        : "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
                            label         : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            itemStyle     : {
                                opacity: 0.5
                            },
                            data          : [0, 0, 0, 89.53, 0]
                        },
                        {
                            name          : "<15",
                            type          : "pictorialBar",
                            barCategoryGap: "-50%",
                            symbol        : "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
                            label         : {
                                show     : true,
                                position : "top",
                                formatter: function (param) {
                                    return param.value ? param.value : "";
                                }
                            },
                            itemStyle     : {
                                opacity: 0.5
                            },
                            data          : [0, 0, 0, 0, 13.2]
                        }
                    ]
                }
            }
        });


        _this.leftPanel
        // .append(_this.leftPanel.lengthChartBlock)
            .append(_this.leftPanel.PQIChartBlock)
            .append(_this.leftPanel.roadDamageChartBlock)
        ;

        _this.rightPanel = new FloatPanel({"class": "rightPanel", "showMinMax": true, "title": "养护 / 拥堵"});

        _this.rightPanel.maintainChartBlock = new ChartBlock({
            "title": "道路养护费用变化统计",
            "chart": {
                "height"     : 270,
                "width"      : 350,
                "chartOption": {
                    grid  : {
                        top         : "40px",
                        left        : "0",
                        right       : "40px",
                        bottom      : "0",
                        containLabel: true
                    },
                    xAxis : {
                        name: "年",
                        type: "category",
                        data: [2017, 2018, 2019, 2020, 2021, 2022]
                    },
                    yAxis : {
                        name    : "万元",
                        type    : "value",
                        axisLine: {
                            show: true
                        }
                    },
                    series: [
                        {
                            type : "bar",
                            data : [184.811, 319.864, 448.907, 733.268, 265.065, 553.288],
                            label: {
                                show    : true,
                                position: "top"
                            }
                        }
                    ]
                }
            }
        });

        _this.rightPanel.traficChartBlock = new ChartBlock({
            "title": "道路交通拥堵路况变化统计",
            "chart": {
                "height"     : 270,
                "width"      : 350,
                "chartOption": {
                    legend : {
                        data: ["上行", "下行"]
                    },
                    grid   : {
                        top         : "80px",
                        left        : "0",
                        right       : "50px",
                        bottom      : "0",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    xAxis  : {
                        name: "辆/日",
                        type: "category",
                        data: [
                            "[5000,10000]",
                            "[10000,15000]",
                            "[15000,20000]",
                            "[20000,25000]",
                            ">25000"
                        ]
                    },
                    yAxis  : {
                        name    : "公里",
                        type    : "value",
                        axisLine: {
                            show: true
                        }
                    },
                    series : [
                        {
                            name     : "上行",
                            stack    : "total",
                            type     : "bar",
                            data     : [40, 220, 130, 20, 60],
                            itemStyle: {
                                color: "#0cf"
                            }
                        },
                        {
                            name     : "下行",
                            stack    : "total",
                            type     : "bar",
                            data     : [30, 160, 130, 10, 60],
                            itemStyle: {
                                color: "#f0a"
                            }
                        }
                    ]
                }
            }
        });


        _this.rightPanel
            .append(_this.rightPanel.maintainChartBlock)
            .append(_this.rightPanel.traficChartBlock);

        _this.app.ui.layout.left.append(_this.leftPanel);
        _this.app.ui.layout.right.append(_this.rightPanel);

    }

    var _class = HomeNSModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "open"              : {
            value: function (stopPropagation) {

                var _this = this;

                if (!_this.isOpened) {

                    _this.leftPanel.open(false);
                    _this.leftPanel.max(false);
                    _this.rightPanel.open(false);
                    _this.rightPanel.max(false);
                    _this.app.flyHome(true);
                    _this.isOpened = true;
                    stopPropagation !== false && _this.trigger("open");
                }
            }
        },
        "close"             : {
            value: function (stopPropagation) {

                var _this = this;

                if (_this.isOpened) {
                    _this.leftPanel.close();
                    _this.rightPanel.close();
                    _this.isOpened = false;
                    stopPropagation !== false && _this.trigger("close");
                }
            }
        },
        "toggle"            : {
            value: function () {
                var _this = this;
                if (_this.isOpened) {
                    _this.close();
                } else {
                    _this.open();
                }
            }
        },
        "createModuleButton": {
            value: function (option) {
                var _this = this;

                var button = new EquipmentListItem(option);

                if (button.module) {
                    button.on("click", function () {
                        button.module.toggle(false);
                        button.toggleClass("active");
                    });
                }

                return button;


            }
        }
    });

    return _class;

});